package com.cet.qz.unit01.chapter1_4;

/**
 * @program: algorithm
 * @description: 两个较大的int值相加溢出解决,用long类型来接收
 * @author: 陈恩涛
 * @create: 2021-05-22 22:51
 **/
public class Qz1_4_2 {

    public static int threeSum(int[] a) {
        int l = a.length;
        int count = 0;
        long sum = 0L;
        for (int i = 0; i < l; i++) {
            for (int j = i + 1; j < l; j++) {
                for (int k = j + 1; k < l; k++) {
                    sum = a[i] + a[j];
                    if (a[k] == -sum) {
                        count ++ ;
                    }
                }
            }
        }

        return count;
    }


    public static void main(String[] args) {
        int[] a = {555555553,555555552,1,2};
        System.out.println(threeSum(a));
    }
}
